#ifndef DECODER_H
#define DECODER_H

#include "BitStream.h"
#include "DecoderSettings.h"
#include "QuantizationMatrix.h"
#include "BitStream.h"
#include "BlockList.h"
#include "Matrix.h"
#include "parallelSettings.h"

using util::BitStreamReader;

class Decoder
{
private:
	Matrix _DCTMatrix;
	Matrix _tDCTMatrix;
	Matrix _imageMatrix;
	BlockList _decompressedData;
	QuantizationMatrix *_quantizationMatrix;
	void initDCTMatrices();
	double _imageList[16];
	void multiplyMatrix(float* first, float* second, float* resultStorage);
	float calculateMatrixMultElement(int pos, float* first, float* second);
	int _totalBlocks;
	int _width;
	int _height;
	int _columnLength;
	int _motionCompensation;
public:
	Decoder();
	Decoder(int width, int height, QuantizationMatrix *qm, int columnLength);
	Decoder(DecoderSettings& config, QuantizationMatrix *qm, int columnLength);
	uint8_t* decode(BitStreamReader& bsr);
	uint8_t* decodePFrame(BitStreamReader& bsr, uint8_t* previousFrame);
	double* performRLDecoding(BitStreamReader& bsr);
	void performDeZigZag(double* list, Matrix& m);
	void performDeQuantization(Matrix& m);
	void performIDCT(Matrix& m);
};

#endif // DECODER_H